﻿using System;

namespace ShuttleBus.Transports.Msmq
{
    internal static class UriExtensions
    {
        public static string ToMsmqPath(this Uri uri)
        {
            var host = uri.Host;
            var queueName = uri.AbsolutePath.Substring(1);

            if (string.Equals(host, ".") ||
                string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(host, Environment.MachineName, StringComparison.OrdinalIgnoreCase))
            {
                return Environment.MachineName + "\\private$\\" + queueName;
            }

            return string.Format(@"FormatName:DIRECT=OS:{0}\private$\{1}", host, queueName);
        }
    }
}